package com.cdut.hwadeefsc.mapper;

import com.cdut.hwadeefsc.entity.activities;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface activitiesMapper { // 接口名首字母大写

    @Select("SELECT * FROM activities WHERE class_id = #{classId} ORDER BY activity_date DESC")
    List<activities> findByClassId(Long classId); // 参数类型改为Long

    @Select("SELECT * FROM activities ORDER BY activity_date DESC")
    List<activities> findAll();

    @Select("SELECT a.* FROM activities a " +
            "JOIN class_students cs ON a.class_id = cs.class_id " +
            "WHERE cs.student_id = #{studentId} ORDER BY a.activity_date DESC")
    List<activities> findByStudentId(Long studentId); // 参数类型改为Long

    @Select("SELECT * FROM activities WHERE id = #{id}")
    activities findById(Long id); // 参数类型改为Long

    @Insert("INSERT INTO activities (class_id, author_id, activity_title, activity_content, " +
            "activity_date, location, status, photo_urls, created_at) " + // 修正字段名：organizer_id→author_id，create_time→created_at
            "VALUES (#{classId}, #{authorId}, #{activityTitle}, #{activityContent}, " + // 修正参数：organizerId→authorId，createTime→createdAt
            "#{activityDate}, #{location}, #{status}, #{photoUrls}, #{createdAt})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(activities activity);

    @Update("UPDATE activities SET activity_title = #{activityTitle}, activity_content = #{activityContent}, " +
            "activity_date = #{activityDate}, location = #{location}, status = #{status}, " +
            "photo_urls = #{photoUrls}, updated_at = #{updatedAt} " + // 新增更新时间字段
            "WHERE id = #{id}")
    int update(activities activity);

    @Delete("DELETE FROM activities WHERE id = #{id}")
    int delete(Long id); // 参数类型改为Long

    @Select("SELECT * FROM activities WHERE status = #{status} ORDER BY activity_date DESC")
    List<activities> findByStatus(String status);
}






